import cv2 as cv

image = cv.imread('/Users/apple/Desktop/data/lena.jpg')
cv.imshow('before image', image)


# 高斯平滑
blurImg = cv.GaussianBlur(image, (5, 5), 0)
cv.imshow('after image', blurImg)


# 缩放到原来的四分之一，输出尺寸格式为宽高
# method 1:
x, y = image.shape[0:2]
resImg = cv.resize(image, (int(y/2), int(x/2)))
# method 2:
resImg = cv.resize(image, (0,0), fx=0.5, fy=0.5, interpolation=cv.INTER_CUBIC)
# method 3:
resImg = cv.pyrDown(image)
cv.imshow('resize image', resImg)


# 颜色空间转换、阈值化
greImg = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
cv.imshow('grey image', greImg)

# 黑白图像
ret,bwImg = cv.threshold(greImg, 120, 255, cv.THRESH_BINARY)
cv.imshow('threshold image', bwImg)

cv.waitKey()
cv.destroyAllWindows()
